#!/usr/bin/env python
# -*- coding: utf-8 -*-
###########################################################################
#   Copyright (C) 2008 by Serj Poltavsky                                  #
#   serge.uliss at gmail.com                                              #
#                                                                         #
#   This program is free software; you can redistribute it and/or modify  #
#   it under the terms of the GNU General Public License as published by  #
#   the Free Software Foundation; either version 3 of the License, or     #
#   (at your option) any later version.                                   #
#                                                                         #
#   This program is distributed in the hope that it will be useful,       #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#   GNU General Public License for more details.                          #
#                                                                         #
#   You should have received a copy of the GNU General Public License     #
#   along with this program. If not, see <http://www.gnu.org/licenses/>   #
###########################################################################

import unittest
from dvdauthor.dvdauthor import DvdAuthor
from dvdauthor.video import Video

class TestVideo(unittest.TestCase):
    def setUp(self):
        dvd = DvdAuthor()
        self.v = Video(dvd)

    def test_init(self):
        self.assertEqual(self.v.format, "pal")
        self.assertEqual(self.v.aspect, (4, 3))
        self.assertEqual(self.v.node.localName, "video")

    def test_format(self):
        self.v.format = "pal"
        self.assertEqual(self.v.format, "pal")
        self.v.format = None
        self.assertEqual(self.v.format, None)
        self.v.format = "ntsc"
        self.assertEqual(self.v.format, "ntsc")
        self.assertRaises(ValueError, self.v.set_format, "SECAM")

    def test_aspect(self):
        self.v.aspect = None
        self.assert_(self.v.aspect is None)
        self.v.aspect = [16, 9]
        self.assertEqual(self.v.aspect, (16, 9))
        self.v.aspect = (4, 3)
        self.assertEqual(self.v.aspect, (4, 3))
        self.assertRaises(ValueError, self.v.set_aspect, (3,4))

    def test_widescreen(self):
        vals = (None, "crop", "noletterbox", "nopanscan")
        for wd in vals:
            self.v.widescreen = wd
            self.assertEqual(wd, self.v.widescreen)
        self.assertRaises(ValueError, self.v.set_widescreen, "foo")

    def test_update(self):
        self.v.format = "pal"
        self.v.aspect = (4,3)
        self.v.widescreen = "crop"

        self.v.update()
        n = self.v.node
        self.assertEqual(n.getAttribute("format"), "pal")
        self.assertEqual(n.getAttribute("aspect"), "4:3")
        self.assertEqual(n.getAttribute("widescreen"), "crop")

        self.v.format = None
        self.v.update()
        self.assertEqual(n.getAttribute("format"), '')
        self.assertEqual(n.getAttribute("aspect"), "4:3")
        self.assertEqual(n.getAttribute("widescreen"), "crop")

        self.v.aspect = None
        self.v.update()
        self.assertEqual(n.getAttribute("format"), '')
        self.assertEqual(n.getAttribute("aspect"), '')
        self.assertEqual(n.getAttribute("widescreen"), "crop")